// WebSocket.hpp
#pragma once
#include <string>
#include <vector>
#include "muduo/server.hpp"

class WebSocket {
public:
    enum Opcode {
        CONTINUATION = 0x0,
        TEXT = 0x1,
        BINARY = 0x2,
        CLOSE = 0x8,
        PING = 0x9,
        PONG = 0xA
    };

    // WebSocket 握手处理
    static bool handleHandshake(const std::string& request, std::string& response);
    
    // WebSocket 帧编码
    static std::string encodeFrame(const std::string& message, Opcode opcode = TEXT);
    
    // WebSocket 帧解码
    static bool decodeFrame(const char* data, size_t len, std::string& message, Opcode& opcode);
    
private:
    static std::string generateAcceptKey(const std::string& key);
    static std::string base64Encode(const std::string& data);
    static std::string sha1Hash(const std::string& data);
};